import { Body, Inject, Post, Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core';
import { BaseSysUserEntity } from '../../../entity/sys/user';
import { BaseSysUserService } from '../../../service/sys/user';

/**
 * 系统用户
 */
@Provide()
@CoolController({
	api: ['add', 'delete', 'update', 'info', 'list', 'page'],
	entity: BaseSysUserEntity,
	service: BaseSysUserService,
	// 分页查询配置
	pageQueryOp: {
		fieldEq: ['departmentId'],
		keyWordLikeFields: ['name'],
		// 增加其他条件
		where: async () => {
			return [
				['username != :username', { username: 'admin' }],
			]
		},
	},
})
export class BaseSysUserController extends BaseController {
	@Inject()
	baseSysUserService: BaseSysUserService;

	/**
	 * 移动部门
	 */
	@Post('/move', { summary: '移动部门' })
	async move(
		@Body('departmentId') departmentId: number,
		@Body('userIds') userIds: []
	) {
		await this.baseSysUserService.move(departmentId, userIds);
		return this.ok();
	}
}
